#include "myOpGLViewCanvas.h"

void myOpGLViewCanvas::draw()
{
	 //indique que le code qui arrive est pour GL_Window
     SetCurrent();
     glClearColor(0.0,0.0,0.0,0.0);
     glClear(GL_COLOR_BUFFER_BIT);
     glMatrixMode(GL_PROJECTION);
     //glLoadIdentity();
     glColor3f(1.0,0.0,0.0);
     glPushMatrix();
     if(GetSize().GetWidth()>GetSize().GetHeight())
     {
		   GLint decalage = (GetSize().GetWidth()-GetSize().GetHeight())/2;
		   glViewport(decalage, 0, (GLint)GetSize().GetHeight(), (GLint)GetSize().GetHeight());
     }
	 else
	 {
           GLint decalage = (GetSize().GetHeight()-GetSize().GetWidth())/2;
	       glViewport(0, decalage, (GLint)GetSize().GetWidth(), (GLint)GetSize().GetWidth());
     }
	 glRotatef(angle,0,0,1);
     glBegin(GL_POLYGON);
        glVertex3f(-0.5,-0.5,1);
        glVertex3f(-0.5,0.5,1);
        glVertex3f(0.5,0.5,1);
     glEnd();
	 glPopMatrix();
     SwapBuffers();
     
     angle+=5;
     if(angle>=360)
		 angle = 0;
}

void myOpGLViewCanvas::undraw()
{
     SetCurrent();
     glClear(GL_COLOR_BUFFER_BIT);
     SwapBuffers();
}
